#!/usr/bin/env python
#coding:utf-8

import sys,os
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class mywindow(QWidget):
    def __init__(self):
        super(mywindow,self).__init__()

        self.monpath=r'c:/temp'
        self.pushbutton1=QPushButton(u'测试')
        gridlayout=QGridLayout()
        gridlayout.addWidget(self.pushbutton1,0,0)
        self.setLayout(gridlayout)

        self.pushbutton1.clicked.connect(self.pushbutton1_clicked)

        self.fswatcher = QFileSystemWatcher()
        self.fswatcher.connect(self.fswatcher, SIGNAL('directoryChanged(QString)'), self.directory_changed)
        self.fswatcher.connect(self.fswatcher, SIGNAL('fileChanged(QString)'), self.file_changed)
        self.fswatcher.addPath(self.monpath)
        #self.fschangelist=self.fswatcher.directories()

    def directory_changed(self,path):
        print '[%s] Directory Changed!!!' % (path)

    def file_changed(self,path):
        print '[%s] File Changed!!!' % (path)

    def createmonpath(self):
        monpaths=[]
        walklist=os.walk(r'c:/python26')
        for item in walklist:
            if len(item[1])==0:
                continue
            for vdir in item[1]:
                monpaths.append(os.linesep.join((item[0],vdir)))

    def pushbutton1_clicked(self):
        #仅仅创建需要监控的目录列表就已经很耗时，这个方法行不通，做不到全盘监控，只能监控少量目录文件。
        #self.createmonpath()
        pass

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainwin = mywindow()
    mainwin.show()
    sys.exit(app.exec_())
